package com.ruoyi.point.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.point.pojo.HistoricalAlarm;
import com.ruoyi.point.service.IHistoricalAlarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 历史报警管理Controller
 *
 * @author ruoyi
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/system/alarm")
public class HistoricalAlarmController extends BaseController
{
    @Autowired
    private IHistoricalAlarmService historicalAlarmService;

    /**
     * 查询历史报警管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:alarm:list')")
    @GetMapping("/list")
    public TableDataInfo list(HistoricalAlarm historicalAlarm)
    {
        startPage();
        List<HistoricalAlarm> list = historicalAlarmService.selectHistoricalAlarmList(historicalAlarm);
        return getDataTable(list);
    }

    /**
     * 导出历史报警管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:alarm:export')")
    @Log(title = "历史报警管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HistoricalAlarm historicalAlarm)
    {
        List<HistoricalAlarm> list = historicalAlarmService.selectHistoricalAlarmList(historicalAlarm);
        ExcelUtil<HistoricalAlarm> util = new ExcelUtil<HistoricalAlarm>(HistoricalAlarm.class);
        util.exportExcel(response, list, "历史报警管理数据");
    }

    /**
     * 获取历史报警管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:alarm:query')")
    @GetMapping(value = "/{equipmentId}")
    public AjaxResult getInfo(@PathVariable("equipmentId") Long equipmentId)
    {
        return success(historicalAlarmService.selectHistoricalAlarmByEquipmentId(equipmentId));
    }

    /**
     * 新增历史报警管理
     */
    @PreAuthorize("@ss.hasPermi('system:alarm:add')")
    @Log(title = "历史报警管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HistoricalAlarm historicalAlarm)
    {
        return toAjax(historicalAlarmService.insertHistoricalAlarm(historicalAlarm));
    }

    /**
     * 修改历史报警管理
     */
    @PreAuthorize("@ss.hasPermi('system:alarm:edit')")
    @Log(title = "历史报警管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HistoricalAlarm historicalAlarm)
    {
        return toAjax(historicalAlarmService.updateHistoricalAlarm(historicalAlarm));
    }

    /**
     * 删除历史报警管理
     */
    @PreAuthorize("@ss.hasPermi('system:alarm:remove')")
    @Log(title = "历史报警管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equipmentIds}")
    public AjaxResult remove(@PathVariable Long[] equipmentIds)
    {
        return toAjax(historicalAlarmService.deleteHistoricalAlarmByEquipmentIds(equipmentIds));
    }
}
